package com.supermarket.controller;

import com.supermarket.annotation.OperationLogAnnotation;
import com.supermarket.service.CommonService;
import com.supermarket.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件上传")
@Slf4j
@RestController
@RequestMapping("/common")
@RequiredArgsConstructor
public class CommonController  {


    private final CommonService commonService;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @Operation(summary = "文件上传", description = "上传文件并返回文件URL")
    @ApiImplicitParam(name = "file", value = "上传的文件", required = true, dataType = "file", paramType = "form")
    @PostMapping("/fileUpload")
    @OperationLogAnnotation(operation = "上传文件", operationType = "上传")
    public Result<String> fileUpload(@RequestParam("file") MultipartFile file) {
        String fileUrl = commonService.fileUpload(file);
        return Result.success(fileUrl);
    }
}
